<template>
	<view>
		<view class="container ptb15 plr30">
			<template v-if="questionList.total>0">
				<view class="ques mb20 p30" v-for="(item, index) in questionList.data" @tap="godetail" :data-id="item.id">
					<view class="flex flex-align-start mb20">
						<view class="label">问</view>
						<view class="fs32 col10">{{item.question}}</view>
					</view>
					<view class="flex-box">
						<view class="fs22 col89 flex-grow-1">{{item.createtime_text}}</view>
						<template v-if="user.is_broker==1">
							<view class="btn1" v-if="item.state==1">未回复</view>
							<view class="btn1" v-else>已回复</view>
						</template>
						<template v-else>
							<navigator class="btn2" v-if="item.state==1" :url="'/pages/member/reply/reply?question_id='+item.id" hover-class="none">回复</navigator>
							<view class="btn1" v-else>已回复</view>
						</template>
						
					</view>
				</view>
			
			</template>
			<template v-else>
				<u-empty
				        mode="data"
						text="暂无数据"
						textSize="24"
				        icon="/static/images/none-data.png"
				>
				</u-empty>
			</template>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	
	const functions = require('../../../utils/functions.js');
export default {
	
	data() {
		return {
		
				loadStatus:'loadmore',//加载状态
				house_name: '',
				house_id: 0,
				broker_user_id: 0,
				keyword: '',
				is_has_image: 1,
				//是否有图：1=全部，2=有
				tags_id: 0,
				tagsData: [],
				// 列表
				questionList: {
				    total: 0,
				    current_page: 0,
				    last_page: 1,
				    data: []
				},
				user:''
			
		};
	},
	methods:{
		initData(){
            var that=this
			console.log(that.questionList)
            that.questionList.current_page= 0
			
            that.getquestion();
  
		},
		// 获取列表信息
		getquestion(){	
			console.log(55555555)
			var that = this;
			var user=that.user
			
			
			var json = {
				
			};
			//1=用户 2=经纪人
			if(user.is_broker==1){
				json.type=2
			}else{
				json.type=1
				
			}
			json.page = Number(that.questionList.current_page) + 1;
		
			if (json.page > 1 && that.questionList.current_page >= that.questionList.last_page) {
				functions.toast('已加载到底部了');
				this.loadStatus='nomore';
				return false;
			} 
			this.loadStatus='loading';
			functions.getAjaxList(that, '/api/xiluhouse/Question/my_questions_list', json, function (res) {
				var questionList = res.data;
		
				if (json.page > 1) {
					var now_loadingList_data = that.questionList.data || [];
					var now_loadingList_data = now_loadingList_data.concat(questionList.data);
					questionList.data = now_loadingList_data;
				}
				if(questionList.current_page >= questionList.last_page){
					that.loadStatus='nomore';
				}
		
				that.questionList=questionList
			});
				
		},
		//回复
		reply(e){
			console.log(e.currentTarget.dataset.index)
		},
		godetail(e){
			var id=e.currentTarget.dataset.id
			wx.navigateTo({
				url:'/pages/member/reply_detail/reply_detail?id='+id
			})
		}
	},

	
	
	onPullDownRefresh: function () {
		uni.showNavigationBarLoading(); 
		var that = this; 
		//模拟加载
		setTimeout(function () {
			that.initData();
			uni.stopPullDownRefresh(); //停止下拉刷新
		}, 1500);
	},
	onReachBottom: function () {
		if (this.questionList.current_page >= this.questionList.last_page) {
			this.loadStatus='nomore';
			return false;
		} else {
			this.getquestion();
		}
	},
	onLoad(){
		var that=this
		functions.getAjaxData('/api/xiluhouse/User/index', {}, function (res) {
			app.globalData.userInfo = res.data;
			that.user=res.data
			that.initData()
		});
		
		
	}
};
</script>

<style lang="scss" scoped>
.ques {
	background: #ffffff;
	box-shadow: 0 4rpx 30rpx 0 rgba(184, 189, 202, 0.3);
	border-radius: 10rpx;
}
.ques .label{
	margin-top: 5rpx;
	margin-right: 10rpx;
	width: 40rpx;
	height: 40rpx;
	background: linear-gradient(180deg, #00C4FF 0%, #0091FF 100%);
	border-radius: 10rpx;
	font-size: 24rpx;
	color: #FFFFFF;
	line-height: 40rpx;
	text-align: center;
}
.ques .btn1{
	font-size: 22rpx;
	color: #FF723B;
	line-height: 30rpx;
}
.ques .btn2{
	width: 100rpx;
	height: 50rpx;
	background: #0091FF;
	box-shadow: 0 4rpx 40rpx 0 rgba(3, 103, 179, 0.3);
	border-radius: 5rpx;
	font-size: 22rpx;
	color: #FFFFFF;
	line-height: 50rpx;
	text-align: center;
}
</style>
